#include "widget.h"
#include "ui_widget.h"
#include "math.h"
#include "QString"
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    this->setFixedSize(300,300);
    ui->setupUi(this);
    ui->pushButton->setShortcut(Qt::Key_Return);
//    ui->pushButton->setShortcut(Qt::Key_Enter);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QString s=ui->lineEdit->text();//分子str
    QString t=ui->lineEdit_3->text();//分母str
    double ti=t.toDouble();//分母double
    double a=s.toDouble();//分子double
    double b=log(a/ti)/log(2);
    QString c=QString::number(b);
    ui->lineEdit_2->setText(c);
}

void Widget::keyPressEvent(QKeyEvent *event){
    if(event->key()==Qt::Key_Enter){
        ui->pushButton->clicked();
    }
    else if (event->key()==Qt::Key_Return) {
        ui->pushButton->click();
    }
}




















